from itertools import count
from typing import Iterable


def convert_to_iterator(producer):
    if hasattr(producer, '__next__'):
        return producer
    if isinstance(producer, Iterable):
        return iter(producer)
    if callable(producer):
        return iter(producer() for _ in count())
    raise TypeError(f"The producer is expected to be an iterator (generator) or callable, got {producer}")
